package com.ihunanren.biz.taobao.ao.impl;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Throwables;
import com.ihunanren.biz.common.HnrResourceLoader;
import com.ihunanren.biz.taobao.ao.IHtmlAO;

/**
 * @author kalman03
 */
public class HtmlAO implements IHtmlAO {
	private final static Logger log = LoggerFactory.getLogger(HtmlAO.class);

	private String header;
	private String ad;
	private String footer;
	private String context;
	private String notice;
	
	private boolean init = false;
	
	public void init(){
		try {
			if(!init){
				reloadResources();
			}
		} catch (Exception e) {
			log.error("Catch a exception.",e);
			Throwables.propagate(e);
		}
	}
	
	private void reloadResources() throws IOException{
//		this.header = HnrResourceLoader.getResoureceAsString("header.dat");
//		this.ad = HnrResourceLoader.getResoureceAsString("ad.dat");
//		this.footer = HnrResourceLoader.getResoureceAsString("footer.dat");
//		this.context = HnrResourceLoader.getResoureceAsString("content.dat");
//		this.notice = HnrResourceLoader.getResoureceAsString("notice.dat");
		this.init = true;
	}
	
	@Override
	public String getSpiderDemoHeader() {
		init();
		return header;
	}

	@Override
	public String getSpiderDemoAd() {
		init();
		return ad;
	}

	@Override
	public String getSpiderDemoFooter() {
		init();
		return footer;
	}

	@Override
	public String getContext() {
		init();
		return context;
	}

	@Override
	public String getNotice() {
		init();
		return notice;
	}

}
